$(document).ready(function() {
	$(".package_install").click(package_install);
	$(".package_uninstall").click(package_uninstall);
	$(".package_backup").click(package_backup);
	$(".package_restore").click(package_restore);
});

function package_install(){
	var context=$(this.parentNode.parentNode);
	var package_name=context.attr("id");
	$.ajax({
		url:'/package.package_install',
		dataType: 'json',
		data: {"package_name":package_name,"execute":1},
		success:function(data){
			switch(data.status){
				case "ok" : {
					context.removeClass("package_notinstalled");
					context.addClass("package_installed");
				}
				case "not_installed" : {
					
				}
			}
		}
	});
}


function package_uninstall(){
	var context=$(this.parentNode.parentNode);
	var package_name=context.attr("id");
	$.ajax({
		url:'/package.package_uninstall',
		dataType: 'json',
		data: {"package_name":package_name,"execute":1},
		success:function(data){
			switch(data.status){
				case "ok" : {
					context.removeClass("package_installed");
					context.addClass("package_notinstalled");
				}
				case "not_installed" : {
					
				}
			}
		}
	});
}

function package_backup(){
	var context=$(this.parentNode.parentNode);
	var package_name=context.attr("id");
	$.ajax({
		url:'/package.package_backup',
		dataType: 'json',
		data: {"package_name":package_name,"execute":1},
		success:function(data){
			switch(data.status){
				case "ok" : {
					context.addClass("package_backuped");
				}
				case "no_backup" : {
					
				}
			}
		}
	});
}


function package_restore(){
	var context=$(this.parentNode.parentNode);
	var package_name=context.attr("id");
	$.ajax({
		url:'/package.package_restore',
		dataType: 'json',
		data: {"package_name":package_name,"execute":1},
		success:function(data){
			switch(data.status){
				case "ok" : {
					context.addClass("package_restored");
				}
				case "no_backup" : {
					
				}
			}
		}
	});
}
